<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>博客编辑页</title>
    <!-- 引入 jquery--> 
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> 
    <!-- 引入 editor.md 的依赖 --> 
    <link rel="stylesheet" href="editor.md/css/editormd.min.css" />
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>
    <script src="editor.md/editormd.js"></script>
    <link rel="stylesheet" href="css/blog_edit.css">

    <script>
        function getCookie(name) {
            const value = `; ${document.cookie}`;
            const parts = value.split(`; ${name}=`);
            if (parts.length === 2) return parts.pop().split(';').shift();
        }

        function hasToken() {
            return !!getCookie('token');
        }

        if (!hasToken()) {
            alert("未登录，请登录！");
            window.location.href = 'login_form.html';
        }

    </script>
    <style>
        /* 基本样式 */
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        h2 {
            text-align: center;
            color: #333;
        }

        /* 表单样式 */
        form {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            width: 100%;
            height: 1000px;
            margin: auto;
        }

        label {
            display: block;
            margin-top: 10px;
            margin-bottom: 5px;
            font-weight: bold;
            color: #555;
        }

        input[type="text"], textarea {
            width: 100%;
            padding: 10px;
            margin-top: 5px;
            margin-bottom: 15px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
            font-size: 14px;
            font-family: Arial, sans-serif;
        }

        input[type="submit"] {
            width: 100%;
            padding: 10px;
            background-color: #008cba;
            border: none;
            border-radius: 4px;
            color: white;
            font-size: 16px;
            cursor: pointer;
        }

        input[type="submit"]:hover {
            background-color: #005f7f;
        }
    </style>
</head>
<body>
    <form action="save_article.php" method="POST">
    <!-- 编辑区的容器 -->
    <div class="bolg-edit-container">
        <!-- 博客标题编辑区 -->
        <div class="title">
            
             <input type="text" id="title" name="title"placeholder="请输入文章标题" required>
             <button id="submit">发布文章</button>
        </div>
     
            <!-- 博客编辑器,这里用id是为了和markdown编辑器对接 -->
            <div id="editor" style="height: 100%;">
            <textarea name="content" id="content" style="display: none;"></textarea>
            </div>
        </div>
     
        <script>
            var editor = editormd("editor", {
            // 这里的尺寸必须在这里设置. 设置样式会被 editormd 自动覆盖掉. 
                width: "100%",
            // 设定编辑器高度
                height: "calc(100% -50px)",
            // 编辑器中的初始内容
                markdown: "# 在这里写下一篇博客",
            // 指定 editor.md 依赖的插件路径
                path: "editor.md/lib/",
                onchange: function () {
                    var markdownContent = editor.getMarkdown();
                    document.getElementById('content').value = markdownContent;
                }
                
            });
        
        </script> 
    </form>
</body>
</html>
